<!DOCTYPE html>
<html>
<head>
    <include file="./Application/Home/View/Tpl/head.html" />
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <include file="./Application/Home/View/Tpl/header.html" />



  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        首页
        <small>设备状态</small>
      </h1>
    </section>

    <!-- Main content -->
    <section class="content">
      <!-- Small boxes (Stat box) -->
        <empty name="setcard">
            <div class="col-md-12">
                <div class="alert alert-danger alert-dismissable">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <h4><i class="icon fa fa-ban"></i> 系统提示</h4>
                    组件加载失败，请检查数据库和网络！
                </div>
            </div>
            <else />
            <div class="row">
                <div class="col-md-11  ">
                    <div class="callout callout-info ">
                        <h4>当前GPS位置</h4>
                        <p>经纬度：<span class="label label-success" id="gps">获取中... ...</span></p>
                    </div>
                </div>


            </div>

            <div class="row">
                <div class="  col-lg-6  col-xs-6">
                    <!-- small box -->
                    <div class="small-box bg-yellow">
                        <div class="inner">
                            <h3>{$setcard[0].carddesc}</h3>
                            <p >
                                <if condition="$setcardstatus[0]['sysstate'] eq 'running' ">
                                    <div>
                                        <small class="label label-primary"><i class="fa fa-check-circle"></i> 正常运行中</small>

                                    </div>

                                    <else />
                                    <div>
                                        <small class="label label-danger"><i class="fa fa-close"></i> 组件已停止</small>
                                    </div>
                                </if>
                            </p>
                        </div>
                        <div class="icon">
                            <i class="fa  fa-wifi"></i>

                        </div>
                        <a href="#" class="small-box-footer">  <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div>
                <!-- ./col -->
                <div class="col-lg-5  col-xs-6">
                    <!-- small box -->
                    <div class="small-box bg-green">
                        <div class="inner">
                            <h3>{$setcard[1].carddesc}</h3>
                            <p >
                                <if condition="$setcardstatus[1]['sysstate'] eq 'running' ">
                                    <div>
                                        <small class="label label-primary"><i class="fa fa-check-circle"></i> 正常运行中</small>
                                    </div>
                                    <else />
                                    <div>
                                        <small class="label label-danger"><i class="fa fa-close"></i> 组件已停止</small>
                                    </div>
                                </if>
                            </p>
                        </div>
                        <div class="icon">
                            <i class="fa fa-cloud-download"></i>
                        </div>
                        <a href="#" class="small-box-footer"> <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div>
                <!-- ./col -->
                <div class="   col-lg-4  col-xs-6">
                    <!-- small box -->
                    <div class="small-box  bg-aqua">
                        <div class="inner">
                            <h3>{$setcard[2].carddesc}</h3>
                            <p >
                                <if condition="$setcardstatus[2]['sysstate'] eq 'running' ">
                                    <div>
                                        <small class="label label-primary"><i class="fa fa-check-circle"></i> 正常运行中</small>
                                    </div>
                                    <else />
                                    <div>
                                        <small class="label label-danger"><i class="fa fa-close"></i> 组件已停止</small>
                                    </div>
                                </if>
                            </p>
                        </div>
                        <div class="icon">
                            <i class="fa fa-user-times"></i>
                        </div>
                        <a href="#" class="small-box-footer"> <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div>
                <!-- ./col -->
                <div class="col-lg-4  col-xs-6">
                    <!-- small box -->
                    <div class="small-box bg-red">
                        <div class="inner">
                            <h3>{$setcard[3].carddesc}</h3>

                            <p >
                                <if condition="$setcardstatus[3]['sysstate'] eq 'running' ">
                                    <div>
                                        <small class="label label-primary"><i class="fa fa-check-circle"></i> 正常运行中</small>
                                    </div>
                                    <else />
                                    <div>
                                        <small class="label label-danger"><i class="fa fa-close"></i> 组件已停止</small>
                                    </div>
                                </if>
                            </p>
                        </div>
                        <div class="icon">
                            <if condition="$setcard[3]['cardtype'] eq '4' ">
                                <if condition="$wzwifistatus['ssid'] neq null">
                                    <button class="btn   btn-success  btn-lg wzwifi" id="mainwzwifi" action="stop"   type="button"  >
                                         停止伪装
                                    </button>
                                <else />
                                    <button class="btn    btn-primary  btn-lg wzwifi" id="mainwzwifi" action="start"  type="button" >
                                         开启伪装
                                    </button>
                                </if>
                                <else />
                                <i class="fa fa-user-o"></i>
                            </if>

                        </div>
                            <if condition="$wzwifistatus['ssid'] neq null">
                                <span id="wzstatus">
                                    SSID:{$wzwifistatus['ssid']} 秘钥：{$wzwifistatus['key']} 加密方式：{$wzwifistatus['encrypt']}
                                </span>
                            <else />
                                <span id="wzstatus"></span>
                            </if>

                        <a href="#" class="small-box-footer"> <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div>


                <div class="col-lg-3  col-xs-6">
                    <!-- small box -->
                    <div class="small-box bg-danger">
                        <div class="inner">
                            <h3>蜜罐</h3>
                            <p >
                            <div> &nbsp; </div>
                            </p>
                        </div>
                        <div class="icon">
                            <if condition="$miguanstatus['ssid'] neq null">
                                <button class="btn   btn-success  btn-lg miguan" id="miguan" action="stop"   type="button"  >
                                    关闭蜜罐
                                </button>
                                <else />
                                <button class="btn    btn-danger  btn-lg miguan" id="miguan" action="start"    type="button" >
                                    开启蜜罐
                                </button>
                            </if>
                        </div>
                        <if condition="$miguanstatus['ssid'] neq null">
                                <span id="miguanstatus">
                                    蜜罐运行中... ...
                                </span>
                            <else />
                            <span id="miguanstatus"></span>
                        </if>
                        <a href="#" class="small-box-footer"> <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div>
                <!-- ./col -->
            </div>
        </empty>

      <!-- /.row -->

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

    <div class="modal   fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">手工伪装设置</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group  ">
                        <label class="control-label" for="ssid"> SSID</label>
                        <input type="text" class="form-control"  id="ssid" placeholder="请填写伪装的SSID名称 ...">
                    </div>
                    <div class="form-group  ">
                        <label class="control-label" for="xd"> 信道</label>
                        <input type="text" class="form-control" id="xd" placeholder="请填写信道 ...">
                    </div>

                    <div class="form-group  ">
                        <label class="control-label" for="encrypt"> 加密方式</label>
                        <select class="form-control"  id="encrypt" >
                            <option value="WPA">WPA</option>
                            <option value="WPA2">WPA2</option>
                            <option value="WPA-WPA2">WPA/WPA2</option>
                            <option value="WEP">WEP</option>
                            <option value="NONE">OPEN</option>
                        </select>
                    </div>
                    <div class="form-group  ">
                        <label class="control-label" for="key"> 加密秘钥</label>
                        <input type="text" class="form-control" id="key" placeholder="请填写加密秘钥 ...">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="wzwifi">开始伪装</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>

    <div class="modal   fade miguanmodal" id="myModalmiguan" tabindex="-1" role="dialog" aria-labelledby="myModalmiguan" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">蜜罐设置</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group  ">
                        <input type="file" id="filenames" />
                        <div id="text"></div>
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="setmiguan">开启蜜罐</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>


    <include file="./Application/Home/View/Tpl/footer.html" />


  <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->
<input type="hidden" id="uploadfilecontent" name="uploadfilecontent">
<include file="./Application/Home/View/Tpl/commjs.html" />


<script type="text/javascript">


    $("#wzwifi").click(function(){
        if($("#ssid").val().trim()==""){
            alert('请填写ssid');
            return;
        }
        if($("#key").val().length<8){
            alert('密码至少8位');
            return;
        }
        $(this).button('loading');
        var btn=$(this);
        var action="start";

        var xd = $("#xd").val();
        var ssid =  $("#ssid").val();
        var encrypt =  $("#encrypt").val();
        var key = $("#key").val();

        $.ajax({
            url : "{:U('/Home/scanwifi/WZWifi','',false)}",
            type : "post",
            dataType : "json",
            data: {action:action, xd: xd, ssid:ssid,encrypt:encrypt,key:key},
            timeout:30000,
            success:function(result){
                btn.button('reset');
                console.log(result);

                $('#myModal').modal('toggle');
                var wzhtml="SSID:"+ ssid +" 秘钥："+key+" 加密方式："+encrypt;

                $("#wzstatus").html(wzhtml);
                if(action=="start"){
                    $("#mainwzwifi").attr('action','stop');
                    $("#mainwzwifi").html('停止伪装');
                    $("#mainwzwifi").attr('class','btn   btn-success btn-lg');
                }
                else{
                    $("#mainwzwifi").attr('action','start');
                    $("#mainwzwifi").html('开始伪装');
                    $("#mainwzwifi").attr('class','btn   btn-primary btn-lg');
                }
            },
            error:function(msg){
                console.log(msg);      //执行错误
                alert("系统错误!");
                btn.button('reset');
            }

        });
    });

    $("#mainwzwifi").click(function(){
        if($("#mainwzwifi").attr('action')=="start"){
            $('#myModal').modal('show');
        }
        else{
            $("#mainwzwifi").attr('action','start');
            $("#mainwzwifi").html('开始伪装');
            $("#mainwzwifi").attr('class','btn   btn-primary btn-lg');
            $("#wzstatus").html('');
            $.ajax({
                url : "{:U('/Home/scanwifi/WZWifi','',false)}",
                type : "post",
                dataType : "json",
                data: {action:'stop'},
                timeout:30000,
                success:function(result){
                },
                error:function(msg){
                    console.log(msg);
                }

            });
        }
    });

    $("#miguan").click(function(){
        if($("#miguan").attr('action')=='start'){
            $('#myModalmiguan').modal('show');
        }
        else{
            $("#miguan").attr('action','start');
            $("#miguan").html('开启蜜罐');
            $("#miguan").attr('class','btn   btn-danger btn-lg');
            $("#miguanstatus").html('');
            var action='stop';
            $.ajax({
                url : "{:U('/Home/index/APCamouflageAct','',false)}",
                type : "post",
                dataType : "json",
                data: {action:action,ssid:''},
                timeout:30000,
                success:function(result){
                },
                error:function(msg){
                    console.log(msg);
                }

            });
        }
    });

    $("#setmiguan").click(function(){
        var file = document.getElementById("filenames").files[0];
        if(!file){
            alert('请上传蜜罐文件');
            return;
        }
        var reader = new FileReader();
        reader.onload = function()
        {
            $("#uploadfilecontent").val(this.result);
        };
        reader.readAsText(file);
        var action='start';
        $.ajax({
            url : "{:U('/Home/index/APCamouflageAct','',false)}",
            type : "post",
            dataType : "json",
            data: {action:action,ssid:$("#uploadfilecontent").val()},
            timeout:30000,
            success:function(result){
                console.log(result);

                $('#myModalmiguan').modal('toggle');
                var wzhtml="蜜罐运行中... ...";
                $("#miguanstatus").html(wzhtml);
                if(action=="start"){
                    $("#miguan").attr('action','stop');
                    $("#miguan").html('关闭蜜罐');
                    $("#miguan").attr('class','btn   btn-success btn-lg');
                }
                else{
                    $("#miguan").attr('action','start');
                    $("#miguan").html('开启蜜罐');
                    $("#miguan").attr('class','btn   btn-danger btn-lg');
                }
            },
            error:function(msg){
                console.log(msg);      //执行错误
                alert("系统错误!");
            }

        });
    });


    $.ajax({
        url : "{:U('/Home/Index/getgps','',false)}",
        type : "post",
        dataType : "json",
        data: null,
        timeout:30000,
        success:function(result){
            $("#gps").html(result.gps);
        },
        error:function(msg){
            console.log(msg);      //执行错误
        }

    });

</script>

</body>
</html>
